package xj.graph2d.command;

import xj.graph2d.DrawShape;
import xj.graph2d.SimpleDrawDocument;
import xj.graph2d.SimpleDrawView;

public class SetBooleanCommand extends DeltaCommand {

  public static final int ATTR_FILLED = 1;

  public static final int ATTR_SHOW_BORDER = 2;

  public static final int ATTR_SHADOW = 3;

  public static final int ATTR_BLURED = 4;

  public SetBooleanCommand(SimpleDrawView view, SimpleDrawDocument doc,
			   DrawShape shape, int attrType) {
    super(view, doc, shape);
    this.attrType = attrType;
  }

  @Override
  protected void forward() {
    if (shape != null) {
      switch (attrType) {
      case ATTR_FILLED:
	shape.setFilled(!shape.isFilled());
	break;
      case ATTR_SHOW_BORDER:
	shape.showBorder(!shape.isShowBorder());
	break;
      case ATTR_SHADOW:
	shape.setShadow(!shape.isShadow());
	break;
      case ATTR_BLURED:
	shape.setBlured(!shape.isBlured());
	break;
      }
      shape.calculateBounds();
    }
  }

  @Override
  protected void backward() {
    if (shape != null) {
      switch (attrType) {
      case ATTR_FILLED:
	shape.setFilled(!shape.isFilled());
	break;
      case ATTR_SHOW_BORDER:
	shape.showBorder(!shape.isShowBorder());
	break;
      case ATTR_SHADOW:
	shape.setShadow(!shape.isShadow());
	break;
      case ATTR_BLURED:
	shape.setBlured(!shape.isBlured());
	break;
      }
      shape.calculateBounds();
    }
  }

  protected int attrType;

}
